#ifndef __NIGHTSINGLETON_H__
#define __NIGHTSINGLETON_H__

#include "assert.h"


namespace NE
{

	template <typename ClassType>
	class Singleton
	{
	public:
		Singleton(void)
		{
			assert(!_singleton());
			_singleton() = static_cast<ClassType*>(this);
		}
		virtual ~Singleton(void)
		{
			_singleton() = 0;
		}
		inline static ClassType& getSingleton(void)
		{
			assert(_singleton());
			return *_singleton();
		}
		inline static ClassType* getSingletonPtr(void)
		{
			assert(_singleton());
			return _singleton();
		}
	protected:
		inline static ClassType*& _singleton(void)
		{
			static ClassType* singleton = 0;
			return singleton;
		}
	private:
		Singleton(const Singleton&);
		void operator =(const Singleton&);
	};

}


#endif // __SINGLETON_H__